package cn.edu.neusoft.yuejian4.yuejian_4.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.MemoryPolicy;
import com.squareup.picasso.Picasso;

import java.util.List;

import cn.edu.neusoft.yuejian4.yuejian_4.Config.Server;
import cn.edu.neusoft.yuejian4.yuejian_4.R;
import cn.edu.neusoft.yuejian4.yuejian_4.javaBean.MasterClass;

/**
 * Created by Lix on 2018/10/19.
 */

public class MasterClassListAdapter extends RecyclerView.Adapter<MasterClassListAdapter.ViewHolder> {
    private List<MasterClass> mMasterClass;
    private Context mContext;

    public MasterClassListAdapter(Context mContext, List<MasterClass> mMasterClass){
        this.mContext = mContext;
        this.mMasterClass = mMasterClass;
        //mLayoutInflater = LayoutInflater.from(mContext);
    }
    @Override
    public MasterClassListAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.master_class_cardview,parent,false);
        MasterClassListAdapter.ViewHolder holder = new MasterClassListAdapter.ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(MasterClassListAdapter.ViewHolder holder, int position) {
        final MasterClass masterClasss = mMasterClass.get(position);
        holder.mclass_name.setText(masterClasss.getName());
        holder.mclass_intro.setText(masterClasss.getIntro());
        Picasso.with(mContext)
                .load(Server.PIC_URL_J+masterClasss.getPic())
                .placeholder(R.drawable.ic_default_img)
                .memoryPolicy(MemoryPolicy.NO_CACHE)
                .into(holder.mclass_img);

    }

    @Override
    public int getItemCount() {
        return mMasterClass.size();
    }
    static class ViewHolder extends RecyclerView.ViewHolder {

        TextView mclass_name,mclass_intro;
        ImageView mclass_img;

        public ViewHolder(View view){
            super(view);
            mclass_name = (TextView)view.findViewById(R.id.master_class_name);
            mclass_intro = (TextView)view.findViewById(R.id.master_class_intro);
            mclass_img = (ImageView) view.findViewById(R.id.master_class_img);

        }
    }
}
